﻿var UserInfoMgr = {
    log: "ss.user.log",
    userInfo: {
        id: "ss.user.id",
        passWord: "ss.user.pwd",
        openId: "ss.user.openid",
        unpickedNum: "ss.user.unpicknum",
        score: "ss.user.score",
        scale2Cash: "ss.user.scale2cash",
    },
    historyPoi: {
        list: "ss.user.his.poi.list",
    },
    loginStatus: 1,
    logoutStatus: 0,

    isLogIn: function () {
        var isLog = false;
        var logVal = getStorageVal(UserInfoMgr.log);
        if (logVal != null && (Number(logVal) == UserInfoMgr.loginStatus)) {
            isLog = true;
        }
        return isLog;
    },
    logIn: function (id, pwd, unpickedNum, score, scale2Cash) {
        setStorage(UserInfoMgr.log, UserInfoMgr.loginStatus);
        setStorage(UserInfoMgr.userInfo.id, id);
        setStorage(UserInfoMgr.userInfo.passWord, pwd);
        setStorage(UserInfoMgr.userInfo.unpickedNum, unpickedNum);
        setStorage(UserInfoMgr.userInfo.score, score);
        setStorage(UserInfoMgr.userInfo.scale2Cash, scale2Cash);
        ServiceNotifyMgr.startNotifyListener();
    },
    logout: function () {
        ServiceNotifyMgr.stopNotifyListener();
        UserInfoMgr.resetUserBaseInfo();
        UserInfoMgr.resetHistoryPoiList();
        DeliveryAddrMgr.resetDeliveryAddrMgr();
        OrderMgr.resetOrderMgr();
    },
    resetUserBaseInfo: function() {
        setStorage(UserInfoMgr.log, UserInfoMgr.logoutStatus);
        removeStorage(UserInfoMgr.userInfo.id);
        removeStorage(UserInfoMgr.userInfo.passWord);
        removeStorage(UserInfoMgr.userInfo.unpickedNum);
        removeStorage(UserInfoMgr.userInfo.score);
        removeStorage(UserInfoMgr.userInfo.scale2Cash);
    },
    setOpenId: function(openId) {
        setStorage(UserInfoMgr.userInfo.openId, openId);
    },
    getOpenId: function() {
        return getStorageVal(UserInfoMgr.userInfo.openId);
    },
    getUserID: function() {
        var userId = null;
        if (UserInfoMgr.isLogIn()) {
            userId = getStorageVal(UserInfoMgr.userInfo.id);
        }
        return userId;
    },
    getPassWord: function(){
        var password = null;
        if (UserInfoMgr.isLogIn()) {
            password = getStorageVal(UserInfoMgr.userInfo.passWord);
        }
        return password;
    },
    getUnpickNum: function () {
        var unpickNum = 0;
        if (UserInfoMgr.isLogIn()) {
            unpickNum = Number(getStorageVal(UserInfoMgr.userInfo.unpickedNum));
        }
        return unpickNum;
    },
    addunpickNum: function(num) {
        if (UserInfoMgr.isLogIn()) {
            var unpickNum = Number(getStorageVal(UserInfoMgr.userInfo.unpickedNum));
            unpickNum += num;
            setStorage(UserInfoMgr.userInfo.unpickedNum, unpickNum);
        }
    },
    getScore: function () {
        var score = 0;
        if (UserInfoMgr.isLogIn()) {
            score = Number(getStorageVal(UserInfoMgr.userInfo.score));
        }
        return score;
    },
    getscale2Cash: function () {
        var scale2Cash = 0;
        if (UserInfoMgr.isLogIn()) {
            scale2Cash = Number(getStorageVal(UserInfoMgr.userInfo.scale2Cash));
        }
        return scale2Cash;
    },
    setHistoryPoiList: function (hostoryPoiList) {
        if (UserInfoMgr.isLogIn()) {
            setStorage(UserInfoMgr.historyPoi.list, hostoryPoiList);
        }
    },
    getHistoryPoiList: function () {
        var historyPoiList = null;
        if (UserInfoMgr.isLogIn()) {
            historyPoiList = getStorageVal(UserInfoMgr.historyPoi.list);
        }
        return historyPoiList;
    },
    resetHistoryPoiList: function () {
        removeStorage(UserInfoMgr.historyPoi.list);
    },
    getSessionId: function () {
        var sessionId = null;
        if (UserInfoMgr.isLogIn()) {
            var userId = getStorageVal(UserInfoMgr.userInfo.id);
            var password = getStorageVal(UserInfoMgr.userInfo.passWord);
            sessionId = {
                "uid": userId,
                "pass_word": password
            };
        }
        return sessionId;
    },
};